package com.xydtech.ecard.imp.controller;

import com.xydtech.common.annotation.Log;
import com.xydtech.common.core.controller.BaseController;
import com.xydtech.common.core.domain.AjaxResult;
import com.xydtech.common.core.page.TableDataInfo;
import com.xydtech.common.enums.BusinessType;
import com.xydtech.common.utils.poi.ExcelUtil;
import com.xydtech.ecard.imp.domain.EcardMerchantImportTask;
import com.xydtech.ecard.imp.service.IEcardMerchantImportTaskService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 网格建档任务Controller
 *
 * @author xydtech
 * @date 2024-11-22
 */
@Controller
@RequestMapping("/ecard/imp/importTask")
public class EcardMerchantImportTaskController extends BaseController {
    private String prefix = "ecard/imp/importTask";

    @Autowired
    private IEcardMerchantImportTaskService ecardMerchantImportTaskService;

    @RequiresPermissions("imp:importTask:view")
    @GetMapping()
    public String importTask() {
        return prefix + "/importTask";
    }

    /**
     * 查询网格建档任务列表
     */
    @RequiresPermissions("imp:importTask:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EcardMerchantImportTask ecardMerchantImportTask) {
        startPage();
        List<EcardMerchantImportTask> list = ecardMerchantImportTaskService.selectEcardMerchantImportTaskList(ecardMerchantImportTask);
        return getDataTable(list);
    }

    /**
     * 导出网格建档任务列表
     */
    @RequiresPermissions("imp:importTask:export")
    @Log(title = "网格建档任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EcardMerchantImportTask ecardMerchantImportTask) {
        List<EcardMerchantImportTask> list = ecardMerchantImportTaskService.selectEcardMerchantImportTaskList(ecardMerchantImportTask);
        ExcelUtil<EcardMerchantImportTask> util = new ExcelUtil<EcardMerchantImportTask>(EcardMerchantImportTask.class);
        return util.exportExcel(list, "网格建档任务数据");
    }

    /**
     * 新增网格建档任务
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存网格建档任务
     */
    @RequiresPermissions("imp:importTask:add")
    @Log(title = "网格建档任务", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EcardMerchantImportTask ecardMerchantImportTask) {
        return toAjax(ecardMerchantImportTaskService.insertEcardMerchantImportTask(ecardMerchantImportTask));
    }

    /**
     * 修改网格建档任务
     */
    @GetMapping("/edit/{taskId}")
    public String edit(@PathVariable("taskId") Long taskId, ModelMap mmap) {
        EcardMerchantImportTask ecardMerchantImportTask = ecardMerchantImportTaskService.selectEcardMerchantImportTaskByTaskId(taskId);
        mmap.put("ecardMerchantImportTask", ecardMerchantImportTask);
        return prefix + "/edit";
    }

    /**
     * 修改保存网格建档任务
     */
    @RequiresPermissions("imp:importTask:edit")
    @Log(title = "网格建档任务", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EcardMerchantImportTask ecardMerchantImportTask) {
        return toAjax(ecardMerchantImportTaskService.updateEcardMerchantImportTask(ecardMerchantImportTask));
    }

    /**
     * 删除网格建档任务
     */
    @RequiresPermissions("imp:importTask:remove")
    @Log(title = "网格建档任务", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(ecardMerchantImportTaskService.deleteEcardMerchantImportTaskByTaskIds(ids));
    }
}
